package cn.tedu.m2;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producter {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.创建连接工厂,并设置连接信息
        ConnectionFactory f1 = new ConnectionFactory();
        f1.setHost("192.168.64.140");
        f1.setPort(5672);
        f1.setUsername("admin");
        f1.setPassword("admin");
        Connection con = f1.newConnection(); //连接
        Channel c = con.createChannel(); //通信的通道
        //创建helloworld-XQ队列
        c.queueDeclare("helloworld-XQQ",true,false,false,null);
        while (true){
            System.out.println("输入消息：");
            String s = new Scanner(System.in).nextLine();
            c.basicPublish("", "helloworld-XQQ", MessageProperties.PERSISTENT_BASIC, s.getBytes());
            System.out.println("消息已发送");
        }

    }
}
